home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Sunday Times: The Month 2004 October
/
The Sunday Times - The Month 2004-10.iso
/
pc
/
assets
/
bespoke
/
kids
/
code
/
code_message.swf
/
scripts
/
frame_1
/
DoAction.as
Wrap
Text File
|
2004-09-06
|
14KB
|
429 lines
_global.MorseCode = new Object();
MorseCode._tl = this;
MorseCode.morseMessageRefs = new Array();
MorseCode.arrIntervals = new Array();
MorseCode.morseMessage = new Array();
MorseCode.currentMorseLetter = new Array();
MorseCode.tilesOnStage = new Array();
MorseCode.numLettersInMessage = 0;
MorseCode.currentMorseLetterSnd = 0;
MorseCode.playLetterCount = 0;
MorseCode.dotSndLen = 79;
MorseCode.sndStartTime;
MorseCode.sndDuration;
MorseCode.totalTileCount = 0;
MorseCode.maxRoundTiles = 27;
MorseCode.tileDepth = 100;
MorseCode.tileBaseX = 12;
MorseCode.tileBaseY = 280;
MorseCode.colCount = 0;
MorseCode.rowCount = 0;
MorseCode.numRows = 5;
MorseCode.numCols = 10;
MorseCode.tilePosIncX = 35;
MorseCode.tilePosIncY = 35;
MorseCode.soundPlaying = false;
MorseCode.xInit = 10;
MorseCode.yInit = 40;
MorseCode.xPos = 10;
MorseCode.yPos = 40;
MorseCode.counter = 0;
theDepth = 999;
MorseCode.keyLimit = false;
MorseCode.lastLetter = new Array();
this.onUnload = function()
{
var _loc1_ = 0;
while(_loc1_ < MorseCode.arrIntervals.length)
{
clearInterval(MorseCode.arrIntervals[_loc1_]);
_loc1_ = _loc1_ + 1;
}
delete MorseCode;
this.unloadMovie();
};
MorseCode.arrMorseCodeAlphabet = {a:"letterA",b:"letterB",c:"letterC",d:"letterD",e:"letterE",f:"letterF",g:"letterG",h:"letterH",i:"letterI",j:"letterJ",k:"letterK",l:"letterL",m:"letterM",n:"letterN",o:"letterO",p:"letterP",q:"letterQ",r:"letterR",s:"letterS",t:"letterT",u:"letterU",v:"letterV",w:"letterW",x:"letterX",y:"letterY",z:"letterZ",§null§:"letterNull"};
MorseCode.arrMorseNumRef = ["zero","one","two","three","four","five","six","seven","eight","nine"];
MorseCode.arrTileIDs = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","null","","three","four","five","six","seven","eight","nine","zero","fullstop","comma","questionmark","colon","semicolon"];
MorseCode.arrEnglishAlphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","null","2","3","4","5","6","7","8","9","0",".",",","?",":",";"];
MorseCode.convertToMorseCode = function(str)
{
var _loc2_ = str;
trace("--------------------------------------------");
trace("convertToMorseCode()");
trace("str: " + _loc2_);
MorseCode.morseMessageRefs = [];
MorseCode.playLetterCount = 0;
i = 0;
while(i < _loc2_.length)
{
var _loc1_ = _loc2_.charCodeAt(i);
if(_loc1_ == 32)
{
_loc1_ = "space";
}
else if(_loc1_ >= 48 && _loc1_ <= 57)
{
_loc1_ = MorseCode.arrMorseNumRef[String.fromCharCode(_loc1_)];
}
else if(_loc1_ == 46)
{
_loc1_ = "fullstop";
}
else if(_loc1_ == 44)
{
_loc1_ = "comma";
}
else if(_loc1_ == 59)
{
_loc1_ = "semicolon";
}
else if(_loc1_ == 58)
{
_loc1_ = "colon";
}
else if(_loc1_ == 63)
{
_loc1_ = "questionmark";
}
else
{
_loc1_ = String.fromCharCode(_loc1_);
}
MorseCode.morseMessageRefs.push(_loc1_);
i++;
}
MorseCode.showMorseMessage();
};
MorseCode.playMorseMessage = function()
{
trace("--------------------------------------------");
trace("playMorseMessage()");
if(MorseCode.playLetterCount < MorseCode.morseMessageRefs.length)
{
MorseCode.playMorseLetter();
}
else
{
MorseCode.soundPlaying = false;
}
trace("--------------------------------------------");
};
MorseCode.playMorseLetter = function(tile, dowbleth)
{
var _loc2_ = tile;
trace("--------------------------------------------");
trace("playMorseLetter()");
if(_loc2_ == undefined)
{
var _loc1_ = 0;
while(_loc1_ < MorseCode.tilesOnStage.length)
{
if(MorseCode.tilesOnStage[_loc1_].ID == MorseCode.morseMessageRefs[MorseCode.playLetterCount].toLowerCase())
{
MorseCode.hiliteTile(MorseCode.tilesOnStage[_loc1_].letterTileBg);
MorseCode.tileToRestore = MorseCode.tilesOnStage[_loc1_];
}
_loc1_ = _loc1_ + 1;
}
if(MorseCode.morseMessageRefs[MorseCode.playLetterCount] == "space")
{
MorseCode.playPause(7);
}
else
{
MorseCode.playSound(MorseCode.morseMessageRefs[MorseCode.playLetterCount]);
}
MorseCode.playLetterCount = MorseCode.playLetterCount + 1;
}
else if(MorseCode.soundPlaying == false)
{
MorseCode.playSound(_loc2_.ID,_loc2_);
if(!dowbleth)
{
MorseCode.showMorseMessage(_loc2_.ID);
}
else
{
MorseCode.showMorseMessage("dowbleth");
trace("hit me with a dowbleth");
}
MorseCode.soundPlaying = true;
MorseCode.tileToRestore = _loc2_;
}
trace("--------------------------------------------");
};
MorseCode.playSound = function(snd, tile)
{
MorseCode.sndStartTime = getTimer();
MorseCode.sndDuration = MorseCode._tl[snd + "_snd"].duration;
trace("tile to highlight: " + tile);
MorseCode._tl[snd + "_snd"].start();
sndID = setInterval(MorseCode.monitorSound,10,0);
MorseCode.arrIntervals.push(sndID);
};
MorseCode.playPause = function(m)
{
MorseCode.sndStartTime = getTimer();
MorseCode.sndDuration = MorseCode.dotSndLen * m;
sndID = setInterval(MorseCode.monitorSound,10,1);
MorseCode.arrIntervals.push(sndID);
};
MorseCode.isEndOfMessage = function()
{
if(MorseCode.playLetterCount == MorseCode.morseMessageRefs.length)
{
trace("tileToRestore: " + MorseCode.tileToRestore);
MorseCode.assignEvents(MorseCode.tileToRestore);
MorseCode.soundPlaying = false;
return true;
}
return false;
};
MorseCode.monitorSound = function(soundOrPause, tile)
{
var _loc1_ = getTimer();
if(soundOrPause == 0)
{
if(_loc1_ >= MorseCode.sndStartTime + MorseCode.sndDuration)
{
MorseCode.deleteInterval(sndID);
if(MorseCode.isEndOfMessage() == false)
{
MorseCode.playPause(3);
}
}
}
else if(_loc1_ >= MorseCode.sndStartTime + MorseCode.sndDuration)
{
MorseCode.deleteInterval(sndID);
MorseCode.playMorseMessage();
}
};
MorseCode.showMorseMessage = function(l)
{
trace("--------------------------------------------");
trace("showMorseMessage()");
if(l == "one")
{
MorseCode.xPos += 30;
}
else if(l == "dowbleth")
{
attachMovie("letterDowbleth","clip" + MorseCode.counter,theDepth++);
clipToEffect = eval("clip" + MorseCode.counter);
clipToEffect._x = MorseCode.xPos;
clipToEffect._y = MorseCode.yPos;
MorseCode.xPos += clipToEffect._width;
}
else
{
attachMovie(MorseCode.arrMorseCodeAlphabet[l],"clip" + MorseCode.counter,theDepth++);
clipToEffect = eval("clip" + MorseCode.counter);
clipToEffect._x = MorseCode.xPos;
clipToEffect._y = MorseCode.yPos;
MorseCode.xPos += clipToEffect._width;
}
if(MorseCode.xPos > 310)
{
MorseCode.xPos = MorseCode.xInit;
MorseCode.YPos += 30;
if(MorseCode.YPos > 180)
{
MorseCode.keyLimit = true;
}
}
MorseCode.counter = MorseCode.counter + 1;
trace("--------------------------------------------");
};
MorseCode.reset = function()
{
MorseCode._tl.message_txt.text = "";
MorseCode._tl.morseCodeMessage = "";
var i = 0;
while(i < MorseCode.arrIntervals.length)
{
clearInterval(MorseCode.arrIntervals[i]);
i++;
}
var i = 0;
while(i < MorseCode.counter)
{
clipToEffect = eval("clip" + i);
removeMovieClip(clipToEffect);
i++;
}
MorseCode.counter = 0;
MorseCode.xPos = MorseCode.xInit;
MorseCode.yPos = MorseCode.yInit;
MorseCode.keyLimit = false;
MorseCode.arrIntervals = [];
stopAllSounds();
MorseCode.soundPlaying = false;
};
MorseCode.addTile = function()
{
var _loc1_ = MorseCode.totalTileCount;
if(MorseCode.totalTileCount == MorseCode.maxRoundTiles)
{
MorseCode._tl["letterTile" + _loc1_]._x = MorseCode.tileBaseX + MorseCode.tilePosIncX * MorseCode.colCount;
MorseCode._tl["letterTile" + _loc1_]._y = MorseCode.tileBaseY + MorseCode.tilePosIncY * MorseCode.rowCount;
MorseCode._tl["letterTile" + _loc1_].ID = MorseCode.arrTileIDs[MorseCode.totalTileCount];
MorseCode._tl["letterTile" + _loc1_].index = MorseCode.totalTileCount;
MorseCode.assignEvents(MorseCode._tl["letterTile" + _loc1_].letterTileBg);
MorseCode.tilesOnStage.push(MorseCode._tl["letterTile" + _loc1_]);
MorseCode._tl.gotoAndPlay("resume");
clearInterval(addTileID);
}
else
{
MorseCode._tl.letterTile.duplicateMovieClip("letterTile" + _loc1_,MorseCode.tileDepth + MorseCode.totalTileCount);
MorseCode._tl["letterTile" + _loc1_]._x = MorseCode.tileBaseX + MorseCode.tilePosIncX * MorseCode.colCount;
MorseCode._tl["letterTile" + _loc1_]._y = MorseCode.tileBaseY + MorseCode.tilePosIncY * MorseCode.rowCount;
if(MorseCode.arrEnglishAlphabet[_loc1_] != "null")
{
MorseCode._tl["letterTile" + _loc1_].letter_txt.text = MorseCode.arrEnglishAlphabet[_loc1_];
}
else
{
MorseCode._tl["letterTile" + _loc1_].letter_txt.html = true;
MorseCode._tl["letterTile" + _loc1_].letter_txt._y += 4;
MorseCode._tl["letterTile" + _loc1_].letter_txt._x -= 1;
var _loc2_ = new TextFormat();
_loc2_.size = "16";
MorseCode._tl["letterTile" + _loc1_].letter_txt.htmlText = "null";
MorseCode._tl["letterTile" + _loc1_].letter_txt.setTextFormat(_loc2_);
}
MorseCode._tl["letterTile" + _loc1_].ID = MorseCode.arrTileIDs[MorseCode.totalTileCount];
MorseCode._tl["letterTile" + _loc1_].index = MorseCode.totalTileCount;
MorseCode.assignEvents(MorseCode._tl["letterTile" + _loc1_].letterTileBg);
MorseCode.tilesOnStage.push(MorseCode._tl["letterTile" + _loc1_]);
MorseCode.colCount = MorseCode.colCount + 1;
if(MorseCode.colCount == MorseCode.numCols)
{
MorseCode.rowCount = MorseCode.rowCount + 1;
if(!(MorseCode.colCount == MorseCode.numCols && MorseCode.rowCount == MorseCode.numRows))
{
MorseCode.colCount = 0;
}
}
}
MorseCode.totalTileCount = MorseCode.totalTileCount + 1;
};
MorseCode.tileRollover = function()
{
myCol = new Color(this);
myCol.setRGB(16041153);
};
MorseCode.tileRollout = function()
{
myCol = new Color(this);
myCol.setRGB(15304833);
};
MorseCode.tilePress = function()
{
var _loc2_ = this;
if(MorseCode.keyLimit == false)
{
MorseCode.hiliteTile(_loc2_);
MorseCode.lastLetter.push(_loc2_._parent.letter_txt.text);
if(MorseCode.lastLetter.length > 2)
{
MorseCode.lastLetter.splice(0,1);
}
if(MorseCode.lastLetter[0] == MorseCode.lastLetter[1])
{
trace("DUPLICATE LETTER!");
MorseCode.lastLetter.splice(0,2);
MorseCode.playMorseLetter(_loc2_._parent,1);
}
else
{
MorseCode.playMorseLetter(_loc2_._parent);
}
var _loc1_ = _loc2_._parent.letter_txt.text;
if(_loc1_ == "SPACE")
{
_loc1_ = " ";
}
if(_loc1_ == "null")
{
_loc1_ = "";
}
if(_loc1_ == "J" || _loc1_ == "V" || _loc1_ == "W")
{
if(error_message._x == undefined)
{
attachMovie("error_message","error_message",theDepth++,{_x:391,_y:143});
}
}
else
{
error_message.removeMovieClip();
}
MorseCode._tl.message_txt.text += _loc1_;
}
};
MorseCode.hiliteTile = function(mc)
{
var _loc1_ = mc;
delete _loc1_.onRollOver;
delete _loc1_.onRollOut;
delete _loc1_.onReleaseOutside;
myCol = new Color(_loc1_);
myCol.setRGB(14824750);
};
MorseCode.assignEvents = function(mc)
{
var _loc1_ = mc;
_loc1_.onRollOver = MorseCode.tileRollover;
_loc1_.onReleaseOutside = _loc1_.onRollOut = MorseCode.tileRollout;
_loc1_.onPress = MorseCode.tilePress;
MorseCode.changeObjCol(_loc1_,15304833);
};
MorseCode.changeObjCol = function(mc, col)
{
myCol = new Color(mc);
myCol.setRGB(col);
};
MorseCode.deleteInterval = function(i)
{
trace("-------------------------------------------");
trace("deleteInterval()");
clearInterval(i);
if(MorseCode.tileToRestore != null)
{
MorseCode.soundPlaying = false;
MorseCode.assignEvents(MorseCode.tileToRestore.letterTileBg);
trace("MorseCode.tileToRestore: " + MorseCode.tileToRestore);
MorseCode.tileToRestore = null;
}
trace("-------------------------------------------");
};
MorseCode.goto = function(dest)
{
var _loc2_ = MorseCode.tilesOnStage.length;
var _loc1_ = 0;
MorseCode._tl.morseCodeMessage = "";
MorseCode._tl.message_txt.text = "";
while(_loc1_ < _loc2_)
{
MorseCode.tilesOnStage[_loc1_].removeMovieClip();
_loc1_ = _loc1_ + 1;
}
_loc1_ = 0;
while(_loc1_ < MorseCode.arrIntervals.length)
{
clearInterval(MorseCode.arrIntervals[_loc1_]);
_loc1_ = _loc1_ + 1;
}
MorseCode.arrIntervals = [];
MorseCode.tilesOnStage = [];
MorseCode._tl.gotoAndPlay(dest);
};
var myListener = new Object();
myListener.onKeyDown = function()
{
trace(Key.getAscii());
};